﻿using System;
using System.Collections.Generic;
using System.Text;
using formworks.DBO;
using formworks.DBO.Core;

using entity;
using formworks.Power;

using Newtonsoft.Json;

namespace formworksTest
{
    class Program
    {
        public static DBSessionFactory factory;
        private static DBSession session;
        //private static Powerful session;
        static void Main(string[] args)
        {

            JavaScriptObject o = new JavaScriptObject();

            o.Add("name", "jcsxc");
            o.Add("age", 23);

            Console.WriteLine(JavaScriptConvert.SerializeObject(o));

            Console.ReadLine();

            //string connectionString = "server=.\\SQLEXPRESS;uid=sa;pwd=123;database=formwork";
            //factory = new DBConfigure(connectionString).buildSessionFactory();

            
<<<<<<< .mine
            //
            session = factory.openSession();
=======
            ////
            //session = factory.openSession();
>>>>>>> .r84

<<<<<<< .mine
            Settings.isQuery = false;
=======
            //Settings.isQuery = false;
>>>>>>> .r84

<<<<<<< .mine
            try
            {
                viewData();
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
=======
            //try
            //{
            //    viewData();
            //}
            //catch(Exception ex)
            //{
            //    Console.WriteLine(ex.Message);
            //}
>>>>>>> .r84
            
<<<<<<< .mine
            
            //session.beginTransaction();
            //addData();
            //updateData();
            //deleteData();
            //session.commit();
            //viewData();
=======
>>>>>>> .r84
            
            ////session.beginTransaction();
            ////addData();
            ////updateData();
            ////deleteData();
            ////session.commit();
            ////viewData();
            
            ////session.rollBack();

            //session.closeSession();

            //Console.ReadLine();
        }


        static void updateData()
        {
            

            Goods item = new Goods();
            item.id = "555";
            item.leavings = 111;
            item.money = 35;
            item.name = "老鼠肉123";
            item.orders = 1911;
            item.stand = "老鼠肉老鼠332";

            session.update<Goods>(item);

            //session.closeSession();
        }


        static void deleteData()
        {
            //DBSession session = factory.openSession();

            //Goods item = new Goods();
            //item.id = "555";
            //item.leavings = 111;
            //item.money = 35;
            //item.name = "老鼠肉";
            //item.orders = 1911;
            //item.stand = "老鼠肉老鼠";

            //session.insert<Goods>(item);

            session.deleteById<Goods>(new string[]{"555"});
            //session.delete<Goods>()

            //session.closeSession();
        }

        static void addData()
        {
            //DBSession session = factory.openSession();

            Goods item = new Goods();
            item.id = "555";
            item.leavings = 111;
            item.money = 35;
            item.name = "老鼠肉";
            item.orders = 1911;
            item.stand = "老鼠肉老鼠";

            session.insert<Goods>(item);

            //session.closeSession();
        }


        static void viewData()
        {
            //DBSession session = factory.openSession();

            List<Goods> goodsList = session.createQuery<Goods>(@"SELECT [id]
                  ,[name]
                  ,[stand]
                  ,[money]
                  ,[leavings]
                  ,[orders]
              FROM [goods]");


            Console.WriteLine("//////////////////////////////////////////////////////////////////////////");
            foreach (Goods item in goodsList)
            {
                Console.WriteLine("id:{0} name{1} money:{2} orders:{3}", 
                    new object[] { item.id, item.name, item.money, item.orders });
            }
            Console.WriteLine("//////////////////////////////////////////////////////////////////////////");

            //session.closeSession();
        }

    }//end class
}//end ms
